n=input()

if not 999<int(n)<10000:
    print('0')
    exit()

n1=n[0]
n2=n[1]
n3=n[2]
n4=n[3]

a=(n1 , n2 , n3, n4 , n1+n2 ,n2+n3 , n3+n4 , n1+n2+n3 , n2+n3+n4, n)
b=[]
for i in a:
    g=True
    for j in range(2, int(i)):
        if int(i)%j==0:
            g=False
            break
    if g==True:
        b.append(int(i))

if len(b)==0:
    print("0")
    exit()

else:
    print(max(b))